package test;

import java.util.Iterator;

import org.hibernate.mapping.Column;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Table;
import org.hibernate.metadata.ClassMetadata;

import test.domain.User;

public class Main {

	public static void main(String[] args) {
		long m = System.currentTimeMillis();
		ClassMetadata cm = HibernateUtil.getSessionFactory().getClassMetadata(User.class);
		
		String[] pns = cm.getPropertyNames();
		for (int i = 0; i < pns.length; i++) {
			System.out.println("p:" + pns[i]);
		}
		
		
		for (Iterator<PersistentClass> it = HibernateUtil.getConfig().getClassMappings(); it.hasNext();) {
			PersistentClass fpc = it.next();
			Table table = fpc.getTable();
			System.out.println(table.getName());
			int max = table.getColumnSpan();
			for(int i=1; i<=max; i++) {
				Column c = table.getColumn(i);
				System.out.println(c + ":" + c.getLength());
			}
		}
		System.out.println("Total used: " + (System.currentTimeMillis() - m ) + "ms");
		/*
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();

		User user = new User();
		user.setUsername("jkyang");
		user.setPassword("1");
		
		session.save(user);

		session.getTransaction().commit();

		HibernateUtil.getSessionFactory().close();
		*/
	}

}
